package cn.org.dian.easycommunicate;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import cn.org.dian.easycommunicate.model.DataCenter;
import cn.org.dian.easycommunicate.util.Utilities;

public class WelcomeActivity extends Activity {

	public static boolean isExiting = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome_activity);

		new AsyncInitTask().execute(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (isExiting) {
			isExiting = false;
			this.finish();
		}
	}

	class AsyncInitTask extends AsyncTask<Context, Void, Void> {

		@Override
		protected Void doInBackground(Context... params) {
			Utilities.init(WelcomeActivity.this);

			DataCenter.init(getResources().openRawResource(
					Utilities.isCurrentLanEng()? R.raw.contenten :R.raw.content));
 			
			
			// wait for a while
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			startActivity(new Intent(WelcomeActivity.this, MainFrame.class));
			return null;
		}

	}
}
